package com.eiot.framework.demo.controller;

import com.eiot.framework.core.utils.CommonUtils;
import com.eiot.framework.demo.dto.req.AddSysUserDto;
import com.eiot.framework.demo.dto.req.DeleteSysUserDto;
import com.eiot.framework.demo.dto.req.QuerySysUserDto;
import com.eiot.framework.demo.dto.req.UpdateSysUserDto;
import com.eiot.framework.demo.entity.SysUser;
import com.eiot.framework.demo.service.ExampleService;
import com.eiot.framework.core.utils.ReturnResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/example")
public class ExampleController {

    @Resource
    ExampleService exampleService;

    /**
     * 查询：查询用户表信息（分页查询）
     */
    @GetMapping("/exampleQuery")
    public List<SysUser> queryUserListByPage(@Validated @RequestBody QuerySysUserDto req)  {
        return exampleService.queryUserListByPage(req);
    }

    /**
     * 新增:新增用户
     */
    @PostMapping("/exampleAdd")
    public ReturnResult addUser(@Validated @RequestBody AddSysUserDto req) {
        return CommonUtils.toAjax(exampleService.addUser(req));
    }

    /**
     * 修改:修改用户
     */
    @PostMapping("/exampleUpdate")
    public ReturnResult updateUser(@Validated @RequestBody UpdateSysUserDto req) {
        return CommonUtils.toAjax(exampleService.updateUser(req));
    }

    /**
     * 删除:删除用户
     */
    @PostMapping("/exampleDelete")
    public ReturnResult deleteUser(@Validated @RequestBody DeleteSysUserDto req) {
        return CommonUtils.toAjax(exampleService.deleteUser(req));
    }

}
